package cn.wolfcode.qo;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Setter
@Getter
//封装查询结果
public class PageResultBak<T> {
    //页面传递的数据
    private int currentPage;//当前页
    private int pageSize;//每一页数据条数
    //数据库查询时传递
    private List<T> data;//查询页显示的内容
    private int totalCount;//总数据条数

    //根据传送过来的数据显示的内容
    private int totalPage;//总页数
    private int prevPage;//上一页
    private int nextPage;//下一页



    public PageResultBak(int currentPage, int pageSize, List<T> data, int totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.data = data;
        this.totalCount = totalCount;

        // 其他事计算出来的
        if(this.totalCount <= this.pageSize)
        {
            this.totalPage = 1;
            this.prevPage = 1;
            this.nextPage = 1;
            return;
        }

        this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize
                : this.totalCount / this.pageSize + 1;
        this.prevPage = this.currentPage == 1 ? 1 : this.currentPage - 1;
        this.nextPage = this.currentPage == this.totalPage ? this.totalPage : this.currentPage + 1;
    }
}
